Skip to content

refactor: remove fileIdentifier/imageObjectRects features - #460

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
pengfeixx:refactor/remove-pdfium2x-features
Nov 26, 2026
Merged

deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
pengfeixx:refactor/remove-pdfium2x-features

Conversation

@pengfeixx

@pengfeixx pengfeixx commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

说明 / Summary

在 #456(切换系统库 libdeepin-pdfium 1.5.8)基础上,通过库导出的 PDFium C API 恢复夜间模式图片对象蒙版功能,功能零损失:

  • 夜间蒙版恢复:libdeepin-pdfium 1.5.8 虽无 Qt 级 imageObjectRects 接口,但导出了完整 PDFium C API(231 个 FPDF_* 符号)。PDFDocument 通过懒加载的第二个 FPDF 文档句柄枚举页面对象(FPDFPage_CountObjects/GetObject),过滤 FPDF_PAGEOBJ_IMAGE 并用 FPDFPageObj_GetBounds 取包围盒,含旋转映射,逻辑与原内嵌实现逐行对齐;加密文档密码从加载链路传入
  • 夜间模式下照片区域保持原色不再负片化,文字/背景照常 CIELAB L* 反转;渲染线程预取、BrowserPage 回贴、缩略图 bbox 缓存(IMAGE_NIGHT_MASK)、夜间图片策略等管线一并恢复
  • fileIdentifier/docId 阅读记录匹配保留:PDFDocument 解析 PDF trailer/xref 字典中的永久 /ID(hex 与字面量语法均支持),解析失败自动回退 fileSize+contentHash 匹配
  • linglong 自编译引擎:玲珑构建通过 sources 克隆 deepin-pdfium(钉住 d9e73d2)源码编译随包分发,不再依赖 apt 版 libdeepin-pdfium

Restore the night-mode image object masks on top of the system libdeepin-pdfium 1.5.8 by using its exported PDFium C API; the /ID-based reading-history matching is kept, and the linglong build now compiles deepin-pdfium from source into the package.

测试建议 / Test

  1. 打开、渲染、缩放、批注并保存 PDF 文档,确认行为正常
  2. 含照片的 PDF 开启夜间模式:照片区域保持原色,文字/背景正常反转;深色主题侧栏缩略图同上
  3. 重命名或移动 PDF(含保存批注后)再打开:阅读记录仍能恢复
  4. deb 与玲珑构建通过(DT_NEEDED 为 libdeepin-pdfium.so.1),批量打印与 html 转 pdf 正常

PMS: TASK-398545

@github-actions

Copy link
Copy Markdown

TAG Bot

TAG: 6.6.6
EXISTED: no
DISTRIBUTION: unstable

@sourcery-ai

sourcery-ai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

API

Move image-object rectangle lookup from the page interface to the document interface, and declare the PDF document’s implementation of the new interface.

  • reader/document/Model.h L193 (removed lines), L239-244
  • reader/document/PDFModel.h L123-130, L145-150 (+2 small edits)

Uses of the API

Route image-object rectangle requests through the new document-level interface so PDF documents can provide the night-mode mask data.

  • reader/uiframe/SheetRenderer.cpp L106-108

Implementation

Implement PDF image-object detection through PDFium, including rotated-page coordinate mapping and password-aware probe loading, and extract the PDF’s persistent identifier from its trailer.

  • reader/document/PDFModel.cpp L22-80, L510-514, L521-611 (+5 small edits)

Configuration

Build and bundle deepin-pdfium from the pinned source revision, adjust package dependencies, and record the package-version update.

  • debian/control L10
  • linglong.yaml L61-89, L146-155 (+3 small edits)

Tests

Add a regression test that checks PDF image-object rectangles are present, positive-sized, and within expected page bounds.

  • tests/document/ut_pdfmodel.cpp L804-822

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 3 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="reader/app/Database.cpp" line_range="387" />
<code_context>
-
-    // docId 未命中时,回退到 fileSize + contentHash 匹配
-    if (bestRow.isEmpty()) {
+    {
         QSqlQuery query(m_database);
+        // 通过 fileSize + contentHash 匹配(同一份内容的移动/重命名/副本)
</code_context>
<issue_to_address>
**Different PDFs inherit reading history**

When two different documents have the same size and identical first and last 64 KB but differ in between, `matchOperationByContent` accepts the sampled `fileSize` and `contentHash` match, so it migrates the other document’s operation state and bookmarks; `setAlive` restores that reading position for the new document.

Verify that the full file contents match before migrating operation state or bookmarks.

Also at `reader/app/Database.cpp:389-393`.
</issue_to_address>

### Comment 2
<location path="reader/app/Database.cpp" line_range="125" />
<code_context>
                     ",fileSize INTEGER DEFAULT 0"
                     ",lastModified INTEGER DEFAULT 0"
                     ",contentHash TEXT DEFAULT ''"
-                    ",docId TEXT DEFAULT ''"
                     ",lastOpened INTEGER DEFAULT 0"
                     ")")) {
</code_context>
<issue_to_address>
**Downgrade cannot save reading state**

When a database is first created by this version and then opened by an older reader release, the older reader’s `saveOperation` still inserts into `operation.docId`; because this schema omits that column and `migrateOperationTable` no longer adds it, saving state after downgrading fails with a missing-column error.

Keep the `docId` column in newly created schemas for backward compatibility, even if this version no longer reads or writes it.
</issue_to_address>

### Comment 3
<location path="reader/app/Database.cpp" line_range="387" />
<code_context>
-
-    // docId 未命中时,回退到 fileSize + contentHash 匹配
-    if (bestRow.isEmpty()) {
+    {
         QSqlQuery query(m_database);
+        // 通过 fileSize + contentHash 匹配(同一份内容的移动/重命名/副本)
</code_context>
<issue_to_address>
**Unhashable files inherit unrelated state**

When the file exists but cannot be opened for hashing, and an unrelated operation row has the same file size and an empty contentHash, `computeContentHash` returns an empty string, and `matchOperationByContent` treats it as a valid content match; a same-sized row with an empty hash is then borrowed or migrated, so the opened file gets another document’s reading state.

Reject content matching when the computed hash is empty, and avoid storing failed hash computations as matchable values.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread reader/app/Database.cpp Outdated

// docId 未命中时,回退到 fileSize + contentHash 匹配
if (bestRow.isEmpty()) {
{

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Different PDFs inherit reading history

When two different documents have the same size and identical first and last 64 KB but differ in between, matchOperationByContent accepts the sampled fileSize and contentHash match, so it migrates the other document’s operation state and bookmarks; setAlive restores that reading position for the new document.

Verify that the full file contents match before migrating operation state or bookmarks.

Also at reader/app/Database.cpp:389-393.

Prompt for AI agents
In `reader/app/Database.cpp` at line 387:

**Different PDFs inherit reading history**

When two different documents have the same size and identical first and last 64 KB but differ in between, `matchOperationByContent` accepts the sampled `fileSize` and `contentHash` match, so it migrates the other document’s operation state and bookmarks; `setAlive` restores that reading position for the new document.

Verify that the full file contents match before migrating operation state or bookmarks.

Also at `reader/app/Database.cpp:389-393`.

Comment thread reader/app/Database.cpp Resolved
Comment thread reader/app/Database.cpp Outdated

// docId 未命中时,回退到 fileSize + contentHash 匹配
if (bestRow.isEmpty()) {
{

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Unhashable files inherit unrelated state

When the file exists but cannot be opened for hashing, and an unrelated operation row has the same file size and an empty contentHash, computeContentHash returns an empty string, and matchOperationByContent treats it as a valid content match; a same-sized row with an empty hash is then borrowed or migrated, so the opened file gets another document’s reading state.

Reject content matching when the computed hash is empty, and avoid storing failed hash computations as matchable values.

Prompt for AI agents
In `reader/app/Database.cpp` at line 387:

**Unhashable files inherit unrelated state**

When the file exists but cannot be opened for hashing, and an unrelated operation row has the same file size and an empty contentHash, `computeContentHash` returns an empty string, and `matchOperationByContent` treats it as a valid content match; a same-sized row with an empty hash is then borrowed or migrated, so the opened file gets another document’s reading state.

Reject content matching when the computed hash is empty, and avoid storing failed hash computations as matchable values.

@pengfeixx
pengfeixx force-pushed the refactor/remove-pdfium2x-features branch 5 times, most recently from 530fc45 to 12fbf9b Compare November 25, 2026 09:02
@pengfeixx

Copy link
Copy Markdown
Contributor Author

/merge

@deepin-bot

deepin-bot Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

This pr cannot be merged! (status: blocked)

1. Restore the imageObjectRects night-mode feature (renderer prefetch,
   BrowserPage paste-back, thumbnail bbox cache, IMAGE_NIGHT_MASK role,
   night image policy options and NightFilter object masks): photos in
   night mode are no longer inverted, only text/background is
2. libdeepin-pdfium 1.5.x lacks the old Qt-level imageObjectRects, but
   exports the full PDFium C API; PDFDocument now enumerates page
   objects (FPDFPage_CountObjects/GetObject/GetBounds with rotation
   mapping) through a lazily created second FPDF document handle, and
   the document password is passed through for encrypted files
3. Keep the fileIdentifier/docId matching: DPdfDoc has no /ID accessor
   on 1.5.x, so PDFDocument parses the permanent /ID straight from the
   PDF trailer/xref dictionary (hex and literal string syntax, latest
   incremental trailer wins)
4. linglong: build deepin-pdfium from source (pinned d9e73d2) into the
   package, replacing the apt libdeepin-pdfium runtime dependency

Influence:
1. Open and render PDF/DOCX/XPS/OFD documents, verify normal reading,
   annotation and printing still work
2. Toggle night mode on a photo-containing PDF: photo areas keep their
   colors (object mask), text/background inverted as before
3. Rename or move a PDF (even after saving annotations) and reopen it:
   reading history still matches via the parsed permanent /ID

refactor: 通过 PDFium C API 探测恢复夜间蒙版功能

1. 恢复 imageObjectRects 夜间模式功能(渲染线程预取、BrowserPage 回贴、
   缩略图 bbox 缓存、IMAGE_NIGHT_MASK 角色、夜间图片策略选项与
   NightFilter 对象蒙版):夜间模式下照片不再被反色,仅文字/背景反转
2. libdeepin-pdfium 1.5.x 缺少原 Qt 级 imageObjectRects 接口,但导出了
   完整 PDFium C API;PDFDocument 通过懒加载的第二个 FPDF 文档句柄枚举
   页面对象(FPDFPage_CountObjects/GetObject/GetBounds,含旋转映射),
   加密文档的密码从加载链路传入
3. 保留 fileIdentifier/docId 阅读记录匹配:libdeepin-pdfium 1.5.x 无
   /ID 接口,PDFDocument 直接解析 PDF trailer/xref 字典中的永久 /ID
   (支持 hex 与字面量两种语法,取最新增量 trailer 的值)
4. 玲珑构建改为源码编译 deepin-pdfium(钉住 d9e73d2)随包分发,
   移除 apt libdeepin-pdfium 运行时依赖

Influence:
1. 打开并渲染 PDF/DOCX/XPS/OFD 文档,验证阅读、批注、打印正常
2. 含照片的 PDF 开启夜间模式:照片区域保持原色(对象蒙版),
   文字/背景照常反转
3. PDF 保存批注后移动/重命名再打开:阅读记录仍按解析出的永久 /ID 匹配

Log: restores the night-mode image mask feature via the PDFium C API exported by libdeepin-pdfium 1.5.8 and builds the engine from source in linglong
PMS: TASK-398545
@pengfeixx
pengfeixx force-pushed the refactor/remove-pdfium2x-features branch from 12fbf9b to 27b1ae1 Compare November 26, 2026 01:52
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lzwind, pengfeixx

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@pengfeixx

Copy link
Copy Markdown
Contributor Author

/merge

@deepin-bot
deepin-bot Bot merged commit b9dc87b into linuxdeepin:master Nov 26, 2026
9 checks passed
@pengfeixx
pengfeixx deleted the refactor/remove-pdfium2x-features branch November 26, 2026 03:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants